//
//  TSFindCategoryCellViewModel.m
//  TaShuo
//
//  Created by N-X on 2018/3/19.
//  Copyright © 2018年 MRNAN. All rights reserved.
//

#import "TSFindCategoryCellViewModel.h"
#import "TSFindCategoryCollectionCell.h"
#import "TSFindCategoryItemViewModel.h"


@interface TSFindCategoryCellViewModel()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@end
@implementation TSFindCategoryCellViewModel

- (void)bindView:(UIView *)view
{
    UICollectionView * collectionView = (UICollectionView *)view;
    collectionView.contentInset = UIEdgeInsetsMake(10, 20, 10, 20);

    collectionView.delegate = self;
    collectionView.dataSource = self;
    //注册cell
    [collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([TSFindCategoryCollectionCell class]) bundle:nil] forCellWithReuseIdentifier:kTsFindCategoryCollectionCellID];
    [collectionView reloadData];
}

#pragma mark -UICollectionViewDelegate && UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.items.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TSFindCategoryCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:kTsFindCategoryCollectionCellID forIndexPath:indexPath];
    TSFindCategoryItemViewModel * itemVM = self.items[indexPath.item];
    [itemVM bindView:cell];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat itemW = (collectionView.nx_width - collectionView.contentInset.left * 2 ) / 5;
    CGFloat itemH = (collectionView.nx_height - collectionView.contentInset.top * 2 )/ 2;
    return CGSizeMake(itemW, itemH);
}
@end
